<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
  <meta charset="utf-8">
  <title>后台管理系统</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="/layui/css/layui.css"  media="all">
</head>
<body>

<div class="search" style="margin-top: 10px">
  进修名称:
<div class='layui-inline'>
<input class='layui-input' name='name' id='name' autocomplete='off'>
</div>
    <!-- 项目编号：
  <div class="layui-inline">
    <input class="layui-input" name="id" id="demoReload_ID" autocomplete="off">
  </div> -->
  <button class="layui-btn" data-type="reload">搜索</button>
  <button onclick="location='/index'" style="float: right" class="layui-btn layui-btn-checked" >返回首页</button>
</div>
<table class="layui-hide" id="test" lay-filter="test"></table>

<script src="/layui/layui.all.js" charset="utf-8"></script>
<!-- 发布状态 -->
<script type="text/html" id="switchTpl">
  <input type="checkbox" data-id="{{d.id}}" name="releaseStatus" value="{{d.releaseStatus}}" lay-skin="switch" lay-text="已发布|未发布" lay-filter="sexDemo" {{ d.releaseStatus == 1 ? 'checked' : '' }}>
</script>
<!-- 头部工具栏 -->
<script type="text/html" id="toolbarDemo">
  <div class="layui-btn-container">
    <shiro:hasRole name="军委机关业务主管部门">
      <button class="layui-btn layui-btn-sm" lay-event="add">新增数据</button>
    </shiro:hasRole>
  </div>
</script>
<script type="text/html" id="barDemo">
  <shiro:hasRole name="业务主管部门">
    {{# if (d.status=== 1) { }}
    　 <a name="admin" class="layui-btn layui-btn-sm" lay-event="audit">审核</a>
      <a name="admin" class="layui-btn layui-btn-sm" lay-event="apply">查看申请人员</a>
    {{# } else if(d.status=== 3) { }}
      <a name="admin" class="layui-btn layui-btn-sm" lay-event="apply">查看申请人员</a>
    {{#  } }}
  </shiro:hasRole>
  <shiro:hasRole name="军委机关业务主管部门">
    {{# if (d.status === null) { }}
      <a name="admin" class="layui-btn layui-btn-sm" lay-event="edit">编辑</a>
      <a class="layui-btn layui-btn-danger layui-btn-sm" lay-event="del">删除</a>
    {{# } else if(d.status=== 2) { }}
      <a name="admin" class="layui-btn layui-btn-sm" lay-event="audit">审核</a>
      <a name="admin" class="layui-btn layui-btn-sm" lay-event="apply">查看申请人员</a>
    {{# } else if(d.status=== 3) { }}
      <a name="admin" class="layui-btn layui-btn-sm" lay-event="apply">查看申请人员</a>
    {{#  } }}

  </shiro:hasRole>

  <shiro:hasRole name="个人用户">
    {{# if (d.status === 1) { }} <!--详见 https://www.cnblogs.com/SeaWxx/p/10173963.html-->

    　<a name="admin" class="layui-btn layui-btn-sm" lay-event="apply">查看申请人员</a>


    {{# } else if(d.status=== null) { }}

      <a name="admin" class="layui-btn layui-btn-sm" lay-event="apply">申请</a>

    {{# } else if(d.status=== 5) { }}

      <a name="admin" class="layui-btn layui-btn-sm" lay-event="apply">查看申请人员</a>

    {{#  } }}
  </shiro:hasRole>

</script>

<script>


  layui.use(['table','form'],function(){
    var table = layui.table,form = layui.form;
    table.render({
      height:'full-60'
      ,elem: '#test'
      ,autoSort:false
      ,toolbar: '#toolbarDemo'
      ,url:'/furtherTraining/list/data'
      ,method:'post'
      ,where: {}
      ,cols: [
        [
          {type:'checkbox'}
          /* ,{field:'id', title: 'id', sort: true} */
          ,{field:'name', title: '锻炼名称', sort: true}
          ,{field:'startDate', title: '锻炼开始日期', sort: true}
          ,{field:'endDate', title: '锻炼结束日期', sort: true}
          ,{field:'num', title: '锻炼人数', sort: true}
          ,{field:'status', title: '锻炼申请状态', sort: true,templet:function(d){
            var t = d.status;
            if(t == 1){
              return "待二级审核"
            }else if (t == 2){
              return "待一级审核"
            }else if (t == 3){
              return "审核通过"
            }else if (t == 4){
              return "审核不通过"
            }else if (t == 5){
              return "人员申请成功"
            }else{
              return "未申请"
            }
          }}
          ,{title:'操作',fixed: 'right', width:200, align:'center', toolbar: '#barDemo'}
        ]
      ]
      ,limit:10
      ,page: true
    });
  
	//监听排序事件 
  table.on('sort(test)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
    console.log(obj.field); //当前排序的字段名
    console.log(obj.type); //当前排序类型：desc（降序）、asc（升序）、null（空对象，默认排序）
    console.log(this); //当前排序的 th 对象
   
    //尽管我们的 table 自带排序功能，但并没有请求服务端。
    //有些时候，你可能需要根据当前排序的字段，重新向服务端发送请求，从而实现服务端排序，如：
    table.reload('test', {
      initSort: obj //记录初始排序，如果不设的话，将无法标记表头的排序状态。
      ,where: { //请求参数（注意：这里面的参数可任意定义，并非下面固定的格式）
        field: obj.field //排序字段
        ,order: obj.type //排序方式
      }
    });
    
    //layer.msg('服务端排序。order by '+ obj.field + ' ' + obj.type);
  });
  //监听工具条
  table.on('tool(test)', function(obj){
	  console.info(obj)
    var data = obj.data;
    if(obj.event === 'detail'){
      layer.msg('ID：'+ data.id + ' 的查看操作');
    } else if(obj.event === 'del'){
      layer.confirm('确定要删除么', function(index){
    	 $.ajax({
    		type:'POST',
    		url:'/furtherTraining/batchDel',
    		data:{ids:data.id},
    		success:function(data){
    			if(data.code==0){
	    			obj.del();
	    	        layer.close(index);    				
    			}else{
    				layer.alert(data.msg)
    			}
    		}
    	}) 
      });
      //审核
    } else if(obj.event === 'audit'){

      layer.confirm('是否通过？', {
        btn: ['通过', '不通过'] //可以无限个按钮
      }, function(index, layero){

        $.ajax({
          type:'POST',
          url:'/furtherTraining/agree',
          data:{id:data.id},
          success:function(data){
            if(data.code==0){
              location.href='/furtherTraining/list'
            }else{
              layer.alert(data.msg)
            }
          }
        })
      }, function(index){
        $.ajax({
          type:'POST',
          url:'/furtherTraining/noAgree',
          data:{id:data.id},
          success:function(data){
            if(data.code==0){
              location.href='/furtherTraining/list'
            }else{
              layer.alert(data.msg)
            }
          }
        })
      });


    }else if(obj.event === 'edit'){
      location.href='/furtherTraining/add?id='+data.id

    }else if(obj.event === 'apply'){

      layer.open({
        type : 2,
        title : '请选择锻炼人才',
        area : [ '800px', '400px' ],
        fixed : false, //不固定
        maxmin : true,
        content :'/furtherTraining/selectPage?id='+data.id
      });
    }
  });


  	var $ = layui.$, active = {
    reload: function(){
      //var demoReload = $('#demoReload');
      var name = $('#name');
      //var id=$("#demoReload_ID");
      //执行重载
      table.reload('test', {
        page: {
          curr: 1 //重新从第 1 页开始
        }
        ,where: {
          name:name.val(),
        	  //name: demoReload.val()
        	  //,templet_id:id.val()
        }
      });
    }
  };
  	
  //头工具栏事件
   table.on('toolbar(test)', function(obj){
     var checkStatus = table.checkStatus(obj.config.id);
     switch(obj.event){
       case 'apply':
         $.ajax({
           type:'POST',
           url:'/people/getPeoplelist',
           data:{},
           success:function(data){
             if(data.code==0){

               layer.open({
                 type : 1,
                 area : [ '350px', '290px' ],
                 fixed : false, //不固定
                 maxmin : true,
                 content :$('#selectPeole')
               });
             }else{
               layer.alert(data.msg)
             }
           }
         })
       break;
       case 'add':
      location.href = '/furtherTraining/add';
      break;
     //同意
       case 'agree':
         var data = checkStatus.data;
         var ids = new Array();
         if(data.length<1) { layer.msg("未选择审核信息"); return false; }
         $.each(data,function(i,n){
           ids[i] = n.id;
         })
         layer.confirm('确定要通过么', function(index){
           $.ajax({
             type:'POST',
             url:'/people/agreeMetor',
             data:{ids:ids.join(",")},
             success:function(data){
               if(data.code==0){
                 location.href='/people/mentorDeclare/list'
               }else{
                 layer.alert(data.msg)
               }
             }
           })
         });
         break;
       //不同意
       case 'noAgree':
         var data = checkStatus.data;
         if(data.length<1) { layer.msg("未选择审核信息"); return false; }
         var ids = new Array();
         $.each(data,function(i,n){
           ids[i] = n.id;
         })
         layer.confirm('确定要拒绝么', function(index){
           $.ajax({
             type:'POST',
             url:'/people/agreeMetor',
             data:{ids:ids.join(",")},
             success:function(data){
               if(data.code==0){
                 location.href='/people/mentorDeclare/list'
               }else{
                 layer.alert(data.msg)
               }
             }
           })
         });
         break;
     };
   });
  //编辑、删除按钮点击事件
    $('.demoTable .layui-btn').on('click', function(){
      var type = $(this).data('type');
      active[type] ? active[type].call(this) : '';
    });
  $('.search .layui-btn').on('click', function(){
    var type = $(this).data('type');
    active[type] ? active[type].call(this) : '';
  });

});


</script>

</body>
</html>


